package com.sayice.gomoku.game;

import com.sayice.gomoku.pojo.Player;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 匹配
 */
public abstract class Match {
    /**
     * 匹配列表
     */
    public static final List<Player> matchList = new CopyOnWriteArrayList<>();
    
    static {
        new Thread(() -> {
            while (true) {
                if (matchList.size() >= 2) {
                    Player player1 = matchList.get(0);
                    Player player2 = matchList.get(1);
                    try {
                        Game.createGame(player1, player2);
                    } catch (IOException e) {
                        e.printStackTrace();
                        throw new RuntimeException(e);
                    }
                }
            }
        }).start();
    }
}
